
// Copyright (C) 2007 Richard Uhler
// This file is part of Esiply.
//
// Esiply is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License, Version 2,
// as published by the Free Software Foundation.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.

#ifndef _HOST_CONTEXT_H_
#define _HOST_CONTEXT_H_


#include <stdio.h>
#include <string>

class HostValue;
class Scope;

class HostContext 
{
public:

    // this constructor not for use by the host
    HostContext(Scope* scope);
    HostContext(const HostContext& rhs);
    HostContext& operator=(const HostContext& rhs);

    // Run the javascript program in the file
    // in the current context. Return the result of running
    // the file.
    HostValue run_file(const std::string& filename);

    // Run the javascript program in the string str in the current
    // context. Return the result of running the string.
    HostValue run_string(const char* str);

    // Execute the javascript program given by str in the current
    // context. Before executing, any non-NULL values will
    // be added to the local scope as $1, $2, $3, $4. After execution
    // the resulting values in $1, $2, $3, $4 will be put into
    // val1, val2, val3, and val4, and the variables $1, $2, $3, $4
    // will be removed from the local scope.
    HostValue host_eval(const char* str, HostValue* val1 = NULL,
            HostValue* val2 = NULL,
            HostValue* val3 = NULL,
            HostValue* val4 = NULL);

    // TODO: not for the host to use! This is internal.
    Scope* get_scope() const;
private:
    Scope* m_scope;
};

#endif//_HOST_CONTEXT_H_

